package com.ruoyi.web.controller.gallery;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.system.domain.gallery.GalleryOriginal;
import com.ruoyi.system.service.gallery.GalleryOriginalService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图库案例原文Controller
 * 
 * @author 张少丛
 * @date 2020-11-30
 */
@RestController
@RequestMapping("/gallery/original")
public class GalleryOriginalController extends BaseController
{
    @Autowired
    private GalleryOriginalService galleryOriginalService;

    /**
     * 查询图库案例原文列表
     */
    @PreAuthorize("@ss.hasPermi('gallery:original:list')")
    @GetMapping("/list")
    public TableDataInfo list(GalleryOriginal galleryOriginal)
    {
        startPage();
        List<GalleryOriginal> list = galleryOriginalService.selectGalleryOriginalList(galleryOriginal);
        return getDataTable(list);
    }

    /**
     * 导出图库案例原文列表
     */
    @PreAuthorize("@ss.hasPermi('gallery:original:export')")
    @Log(title = "图库案例原文", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GalleryOriginal galleryOriginal)
    {
        List<GalleryOriginal> list = galleryOriginalService.selectGalleryOriginalList(galleryOriginal);
        ExcelUtil<GalleryOriginal> util = new ExcelUtil<GalleryOriginal>(GalleryOriginal.class);
        return util.exportExcel(list, "original");
    }

    /**
     * 获取图库案例原文详细信息
     */
    @PreAuthorize("@ss.hasPermi('gallery:original:query')")
    @GetMapping(value = "/{galleryOriginalId}")
    public AjaxResult getInfo(@PathVariable("galleryOriginalId") Long galleryOriginalId)
    {
        return AjaxResult.success(galleryOriginalService.selectGalleryOriginalById(galleryOriginalId));
    }

    /**
     * 新增图库案例原文
     */
    @PreAuthorize("@ss.hasPermi('gallery:original:add')")
    @Log(title = "图库案例原文", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GalleryOriginal galleryOriginal)
    {
        if (UserConstants.NOT_UNIQUE.equals(galleryOriginalService.checkGalleryOriginalById(galleryOriginal.getGalleryInfoId())))
        {
            return AjaxResult.error("新增图库案例原文'" + galleryOriginal.getGalleryOriginalTitle() + "'失败，标题已存在,图库案例原文只能有一条");
        }
        return toAjax(galleryOriginalService.insertGalleryOriginal(galleryOriginal));
    }

    /**
     * 修改图库案例原文
     */
    @PreAuthorize("@ss.hasPermi('gallery:original:edit')")
    @Log(title = "图库案例原文", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GalleryOriginal galleryOriginal)
    {
        return toAjax(galleryOriginalService.updateGalleryOriginal(galleryOriginal));
    }

    /**
     * 删除图库案例原文
     */
    @PreAuthorize("@ss.hasPermi('gallery:original:remove')")
    @Log(title = "图库案例原文", businessType = BusinessType.DELETE)
	@DeleteMapping("/{galleryOriginalIds}")
    public AjaxResult remove(@PathVariable Long[] galleryOriginalIds)
    {
        return toAjax(galleryOriginalService.deleteGalleryOriginalByIds(galleryOriginalIds));
    }
}
